package com.atguigu.springcloud.service.impl;

import com.atguigu.springcloud.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import java.util.UUID;

@EnableBinding(Source.class)//定义消息的推送管道
//import org.springframework.cloud.stream.messaging.Source;
//原来是标注@Service注解将方法注入到spring容器中，这里不再这样了
public class IMessageProviderImpl implements IMessageProvider {
    //这里没有dao不需要操作数据库，这里操作的是消息中间件
    @Autowired
    private MessageChannel output;//消息发送管道
    @Override
    public String send() {
        String s = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(s).build());
        //import org.springframework.integration.support.MessageBuilder;
        System.out.println("+++++++++++++UUID:"+s);
        return s;
    }
}
